Skip to content

Add prompt format strings for socket connections#1563

Merged
rolandwalker merged 1 commit intomainfrom
RW/prompt-escapes-for-sockets
Feb 16, 2026
Merged

Add prompt format strings for socket connections#1563
rolandwalker merged 1 commit intomainfrom
RW/prompt-escapes-for-sockets

Conversation

@rolandwalker
Copy link
Contributor

Description

  • \j - connection socket basename
  • \J - full connection socket path
  • \k - connection socket basename OR the port
  • \K - full connection socket path OR the port

the most handy of which is probably \k, which will show the socket basename if it exists, and if not, the port.

Incidentally, further fix up the prompt commentary in myclirc files.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified new socket related prompt options display as expected.

@rolandwalker rolandwalker force-pushed the RW/prompt-escapes-for-sockets branch from ce909d9 to ee63819 Compare February 16, 2026 08:30
@github-actions
Copy link

Findings

  1. Potential portability bug (Windows paths/named pipes).
    \j, \J, \k, \K use split('/')[-1] to get the basename. This will fail for Windows-style paths or named pipes (e.g. \\.\pipe\MySQL), returning the entire string instead of a basename. Consider os.path.basename (and possibly ntpath.basename) to handle both / and \.
    File: mycli/main.py

Missing tests / edge cases

  1. No coverage for \j, \J, and \K, and for \k when no socket is present (expect port).
    File: test/test_main.py
  2. No test for Windows-style socket paths or named pipes to ensure basename extraction works across platforms.
    File: test/test_main.py

Security

  • No security concerns found in this change.

Notes

  • The new test for \k with socket present is good; it would be stronger with the complementary “socket absent → port” case.

If you want, I can propose the exact test cases or a minimal patch to make basename extraction portable.

@rolandwalker rolandwalker force-pushed the RW/prompt-escapes-for-sockets branch from ee63819 to ca84bf7 Compare February 16, 2026 08:36
 * \j - connection socket basename
 * \J - full connection socket path
 * \k - connection socket basename OR the port
 * \K - full connection socket path OR the port

the most handy of which is probably \k, which will show the socket
basename if it exists, and if not, the port.

Incidentally, further fix up the prompt commentary in myclirc files.
@github-actions
Copy link

Findings (ordered by severity)

  1. Syntax error introduced in prompt replacement code
    • In mycli/main.py, the new string.replace lines for \j and \k are missing closing parentheses, which will make the module fail to import. This is a hard regression.
    • File: mycli/main.py:1404-1407
    • Action: add the missing ) on the \\j and \\k lines.

Missing tests / edge cases

  1. No coverage for \j, \J, \K
    • Only \k is tested. Consider adding cases for \j and \J with a socket set, and for \K with socket unset so it falls back to port.
    • Files: test/test_main.py

Notes

  • I did not run tests.

@rolandwalker rolandwalker force-pushed the RW/prompt-escapes-for-sockets branch from ca84bf7 to f16cd59 Compare February 16, 2026 08:37
@github-actions
Copy link

Findings (ordered by severity)

  1. Potential edge-case output for trailing-slash socket paths
    If sqlexecute.socket ends with a trailing slash (e.g. /var/run/mysqld/), os.path.basename() returns an empty string, so \j or \k would render as empty. Consider normalizing with os.path.normpath before basename, or guard empty to '(none)' / port.
    File: mycli/main.py:1405

  2. Missing tests for new format codes
    Only \k (socket overrides port) is tested. Add tests for \j, \J, and \K including socket absent and socket present cases. Also add a case for an empty string socket (the default in tests now) to confirm \k/\K fall back to port and \j/\J show (none).
    File: test/test_main.py

No security issues spotted.

If you want, I can add the missing tests.

@rolandwalker rolandwalker merged commit f1e0443 into main Feb 16, 2026
10 checks passed
@rolandwalker rolandwalker deleted the RW/prompt-escapes-for-sockets branch February 16, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants